rm(list=ls())
#setwd()
library(ExPosition)

source('InClass_CreateWineDataMatrices.R')

#let's analyze the sensory data.

sensory.pca <- epPCA(wine.sensory)

#is this significant?

nperms <- 100
omni.inertia <- matrix(0,nperms,1)
sv.perms <- matrix(0,nperms,sensory.pca$ExPosition.Data$pdq$ng)
for(i in 1:nperms){
	#Incorrect permutation!
	#wine.sensory.perm <- wine.sensory
	#rownames(wine.sensory.perm)<- sample(rownames(wine.sensory),length(rownames(wine.sensory)))
	
	#let's really permute the data.
	wine.sensory.perm <- apply(wine.sensory,2,sample)
	perm.analysis <- epPCA(wine.sensory.perm,graphs=FALSE)
	#permuted inertia
	omni.inertia[i,1] <- sum(perm.analysis$eigs)
	sv.perms[i,] <- perm.analysis$pdq$Dv
}


#probabilities
(nrow(sv.perms) - colSums(fixed.sv.copy > sv.perms))/nrow(sv.perms)
#and find tails
#and make hist, with pretty things in it.

#do it all again with the other data
#do it again with the combined tables.
	###visit one of our old binding friends.